<?php
declare(strict_types=1);

namespace WebApp\lib\app;

/**
 * Class Resp
 * @package WebApp\lib\app
 */
class Resp
{
    private $response;

    /**
     * Resp constructor.
     * @param $response
     */
    public function __construct(&$response)
    {
        $this->response = $response;
    }

    public function __destruct()
    {
        unset($this->response);
    }

    /**
     * @param string $str
     */
    public function write($str = '')
    {
        if($str){
            if(isset($this->response->write)){
                $func = $this->response->write;
                $func($str);
            }else{
                $this->response->write($str);
            }
        }
    }

    /**
     * @param string $str
     * @return string|bool
     * @throws \Exception
     */
    public function end($str = '')
    {
        $this->write($str);
        throw new \Exception('0');
    }
}